<?php
include '../Module/TemplateModule.php';
$temp=new TemplateModule();
if(isset($_REQUEST["action"])){
    switch ($_REQUEST["action"]){
        case "addItem":
            $name		=isset($_REQUEST["name"])?$_REQUEST["name"]:"";
            $starr		=isset($_REQUEST["starr"])?$_REQUEST["starr"]:"";
            $viewer		=isset($_REQUEST["viewer"])?$_REQUEST["viewer"]:"";
            $image		=isset($_REQUEST["image"])?$_REQUEST["image"]:"";
            $type		=isset($_REQUEST["type"])?$_REQUEST["type"]:"";
            $brief		=isset($_REQUEST["brief"])?$_REQUEST["brief"]:"";
            $des		=isset($_REQUEST["des"])?$_REQUEST["des"]:"";
            $price		=isset($_REQUEST["price"])?$_REQUEST["price"]:"";
            $amount		=isset($_REQUEST["amount"])?$_REQUEST["amount"]:"";
            $name=EndcodeStr($name);
            $brief=EndcodeStr($brief);
            $des=EndcodeStr($des);
            if($temp->insertItem($name, $starr, $viewer, $image, $type, $brief, $des,$price,$amount)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$temp->error;
            }
            break;
        case "add":
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $category		=isset($_REQUEST["category"])?EndcodeStr($_REQUEST["category"]):"";
            $organization       =isset($_REQUEST["organization"])?EndcodeStr($_REQUEST["organization"]):"";
            $starr		=5;
            $viewer		=0;
            $image		=isset($_REQUEST["image"])?EndcodeStr($_REQUEST["image"]):"";
            $img1		=isset($_REQUEST["img1"])?EndcodeStr($_REQUEST["img1"]):"";
            $img2		=isset($_REQUEST["img2"])?EndcodeStr($_REQUEST["img2"]):"";
            $img3		=isset($_REQUEST["img3"])?EndcodeStr($_REQUEST["img3"]):"";
            $img4		=isset($_REQUEST["img4"])?EndcodeStr($_REQUEST["img4"]):"";
            $img5		=isset($_REQUEST["img5"])?EndcodeStr($_REQUEST["img5"]):"";
            $title		=isset($_REQUEST["title"])?EndcodeStr($_REQUEST["title"]):"";
            $_type		=isset($_REQUEST["_type"])?EndcodeStr($_REQUEST["_type"]):"";
            $brief		=isset($_REQUEST["brief"])?EndcodeStr($_REQUEST["brief"]):"";
            $des		=isset($_REQUEST["des"])?EndcodeStr($_REQUEST["des"]):"";
            $price		=isset($_REQUEST["price"])?$_REQUEST["price"]:"";
            $amount		=isset($_REQUEST["amount"])?$_REQUEST["amount"]:"";
            $homepage		=isset($_REQUEST["homepage"])?$_REQUEST["homepage"]:"";
            $web1		=isset($_REQUEST["website1"])?$_REQUEST["website1"]:"";
            if($temp->insertItem($name,$category,$organization,$starr, $viewer, $image,$title,$homepage,$web1,$_type, $brief, $des,$img1,$img2,$img3,$img4,$img5,$price,$amount)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$temp->error;
            }
            break;
        case "edit":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $category		=isset($_REQUEST["category"])?EndcodeStr($_REQUEST["category"]):"";
            $organization       =isset($_REQUEST["organization"])?EndcodeStr($_REQUEST["organization"]):"";
            $starr		=5;
            $viewer		=0;
            $image		=isset($_REQUEST["image"])?EndcodeStr($_REQUEST["image"]):"";
            $img1		=isset($_REQUEST["img1"])?EndcodeStr($_REQUEST["img1"]):"";
            $img2		=isset($_REQUEST["img2"])?EndcodeStr($_REQUEST["img2"]):"";
            $img3		=isset($_REQUEST["img3"])?EndcodeStr($_REQUEST["img3"]):"";
            $img4		=isset($_REQUEST["img4"])?EndcodeStr($_REQUEST["img4"]):"";
            $img5		=isset($_REQUEST["img5"])?EndcodeStr($_REQUEST["img5"]):"";
            $title		=isset($_REQUEST["title"])?EndcodeStr($_REQUEST["title"]):"";
            $_type		=isset($_REQUEST["_type"])?EndcodeStr($_REQUEST["_type"]):"";
            $homepage		=isset($_REQUEST["homepage"])?$_REQUEST["homepage"]:"";
            $web1		=isset($_REQUEST["website1"])?$_REQUEST["website1"]:"";
            $brief		=isset($_REQUEST["brief"])?EndcodeStr($_REQUEST["brief"]):"";
            $des		=isset($_REQUEST["des"])?EndcodeStr($_REQUEST["des"]):"";
            $price		=isset($_REQUEST["price"])?$_REQUEST["price"]:"";
            $amount		=isset($_REQUEST["amount"])?$_REQUEST["amount"]:"";
            if($temp->updateItem($id,$name,$category,$organization,$image,$title,$homepage,$web1, $brief, $des,$img1,$img2,$img3,$img4,$img5,$price,$amount)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$temp->error;
            }
            break;
        case "delete":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($temp->deleteItem($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$temp->error;
            }
            break;
        case "restore":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($temp->restoreItem($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$temp->error;
            }
            break;
    }    
}

function getTemplates(){
    global  $temp;
    return $temp->getTemplates();
}
?>
